<template>
  <div class="sign">
    <!--标题-->
    <div class="logo">
      <img src="@/assets/logo.png" alt="logo">
    </div>
  <div class="main">
    <div class="title">
      <router-link class="active" to='/login' tag="span">登录</router-link>
      <router-link to='/register' tag="span">注册</router-link>
    </div>

    <div class="sign-up-container">
      <el-form ref="userForm" :model="user" >
        <el-form-item class="input-prepend" prop="username" :rules="[{ required: true, message: '请输入用户名', trigger: 'blur' }]">
          <div >
            <el-input type="text" placeholder="用户名" v-model="user.username"/>
          </div>
        </el-form-item>
        <el-form-item class="input-prepend" prop="password"
                      :rules="[{ required: true, message: '请输入密码', trigger: 'blur' }]">
          <div>
            <el-input type="password" placeholder="密码" v-model="user.password"/>
<!--            <i class="iconfont icon-password"/>-->
          </div>
        </el-form-item>
        <el-checkbox v-model="user.isAdmin">以管理员身份登录</el-checkbox>
        <div class="btn">
          <input type="button" class="sign-in-button" value="登录" @click="submitLogin()">
        </div>
      </el-form>
      <!-- 更多登录方式 -->
      <div class="more-sign">
        <h6>社交帐号登录</h6>
        <ul>
          <li><a id="weixin" class="weixin" target="_blank"
                 href="http://qy.free.idcfengye.com/api/ucenter/weixinLogin/login"><i class="iconfont icon-weixin"/></a>
          </li>
          <li><a id="qq" class="qq" target="_blank" href="#"><i class="iconfont icon-qq"/></a></li>
        </ul>
      </div>
    </div>
  </div>
  </div>
</template>


<script>
// import '~/assets/css/sign.css'
// import '~/assets/css/iconfont.css'
export default {
  data() {
    return {
      user: {
        username: '',
        password: '',
        isAdmin: false
      },
    }
  },
  watch: {
    $route: {
      handler: function (route) {
        this.redirect = route.query && route.query.redirect
      },
      immediate: true
    }
  },
  methods: {
    submitLogin() {
          this.$store.dispatch('Login', this.user).then(() => {
            this.$router.push({path: this.redirect || '/'})
          })
    }
  }
}
</script>
<style scoped>
@import url('../../assets/css/sign.css');
@import url('../../assets/css/iconfont.css');
</style>
